﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Imaginecup.shareData;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util.resourceMan;
using Microsoft.Xna.Framework;
using Imaginecup.sprite;
using Imaginecup.sprite.animation;
using imaginecup.util;
using Imaginecup.gameState.intro;
using Imaginecup.util;

namespace Imaginecup.gameState.ending.scene
{
    public class EndingAnimationScene:IScene
    {
        private ISprite m_Sprite;
        private EntityInfo m_Info;
        private AnimationIndexMan m_IndexMan;
        private bool m_bIsComplete;
        private IAnimationLoadContent m_LoadContent;


        public EndingAnimationScene()
        {
            m_Info = new EntityInfo(0, 0, 800, 480);
            m_bIsComplete = false;
        }

        public void SetLoadEndingScene(ILoadContent content)
        {
            m_LoadContent = (IAnimationLoadContent)content;
        }
        public void LoadEndingScene()
        {
            m_IndexMan = m_LoadContent.LoadAnimationIndexMan();
            m_Sprite = m_LoadContent.LoadSprite();
        }

        public void UnloadEndingScene()
        {
            m_Sprite.Release();
            m_LoadContent.UnloadResource();
            m_IndexMan = null;
        }
        
        public void Update(GameTime gameTime)
        {          
            
            m_IndexMan.Update(gameTime);

            if( m_IndexMan.GetCycleCount() == 1 )
            {
                m_IndexMan.SetIndex(m_LoadContent.GetLastIndex() , 0);
                m_IndexMan.StopAnimation();
                m_bIsComplete = true;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            m_Sprite.Draw(spriteBatch, m_Info);
        }

        public bool IsComplete()
        {
            IMouseInputHandler inputHandler = MouseInputHandler.GetInputHandler();
            if (m_bIsComplete )//&& inputHandler.IsOneClick())
                return true;
            return false;
        }
    }
}
